package iit.projects.etaxi.view.bean;


import iit.projects.etaxi.util.JSFUtils;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.MissingResourceException;

import javax.faces.model.SelectItem;

public class StaticValuesBean {
	
	public StaticValuesBean() {
	}
	
	public List<SelectItem> getGenders(){
		String prefix = "gender.values.{0}.";
		String suffixLabel = "label";
		String suffixValue = "value";
		MessageFormat message = new MessageFormat(prefix);
		
		boolean eof = false;
		int i = 1;
		List<SelectItem> selectItems = new ArrayList<SelectItem>();
		while(!eof){
			
			try{
				String formattedString = message.format(new Integer[]{i});
				String label = JSFUtils.getResourcesProperty(formattedString + suffixLabel);
				String value = JSFUtils.getResourcesProperty(formattedString + suffixValue);
				selectItems.add(new SelectItem(value, label));
				i++;
			}catch(MissingResourceException e){
				eof = true;
				return selectItems;
			}
		}
		return selectItems;
	}
	
	public List<SelectItem> getCreditCardTypes(){
		String prefix = "creditcards.values.{0}.";
		String suffixLabel = "label";
		String suffixValue = "value";
		MessageFormat message = new MessageFormat(prefix);
		
		boolean eof = false;
		int i = 1;
		List<SelectItem> selectItems = new ArrayList<SelectItem>();
		while(!eof){
			
			try{
				String formattedString = message.format(new Integer[]{i});
				String label = JSFUtils.getResourcesProperty(formattedString + suffixLabel);
				String value = JSFUtils.getResourcesProperty(formattedString + suffixValue);
				selectItems.add(new SelectItem(value, label));
				i++;
			}catch(MissingResourceException e){
				eof = true;
				return selectItems;
			}
		}
		return selectItems;
	}
	
	public List<SelectItem> getReservationTypes(){
		String prefix = "reservation.types.{0}.";
		String suffixLabel = "label";
		String suffixValue = "value";
		MessageFormat message = new MessageFormat(prefix);
		
		boolean eof = false;
		int i = 1;
		List<SelectItem> selectItems = new ArrayList<SelectItem>();
		while(!eof){
			
			try{
				String formattedString = message.format(new Integer[]{i});
				String label = JSFUtils.getResourcesProperty(formattedString + suffixLabel);
				String value = JSFUtils.getResourcesProperty(formattedString + suffixValue);
				selectItems.add(new SelectItem(value, label));
				i++;
			}catch(MissingResourceException e){
				eof = true;
				return selectItems;
			}
		}
		return selectItems;
	}
	
	public List<SelectItem> getSeatingCapacities(){
		String prefix = "seating.capacity.{0}.";
		String suffixLabel = "label";
		String suffixValue = "value";
		MessageFormat message = new MessageFormat(prefix);
		
		boolean eof = false;
		int i = 1;
		List<SelectItem> selectItems = new ArrayList<SelectItem>();
		while(!eof){
			
			try{
				String formattedString = message.format(new Integer[]{i});
				String label = JSFUtils.getResourcesProperty(formattedString + suffixLabel);
				String value = JSFUtils.getResourcesProperty(formattedString + suffixValue);
				selectItems.add(new SelectItem(value, label));
				i++;
			}catch(MissingResourceException e){
				eof = true;
				return selectItems;
			}
		}
		return selectItems;
	}
	
	public List<SelectItem> getLuggageCapacities(){
		String prefix = "luggage.capacity.{0}.";
		String suffixLabel = "label";
		String suffixValue = "value";
		MessageFormat message = new MessageFormat(prefix);
		
		boolean eof = false;
		int i = 1;
		List<SelectItem> selectItems = new ArrayList<SelectItem>();
		while(!eof){
			
			try{
				String formattedString = message.format(new Integer[]{i});
				String label = JSFUtils.getResourcesProperty(formattedString + suffixLabel);
				String value = JSFUtils.getResourcesProperty(formattedString + suffixValue);
				selectItems.add(new SelectItem(value, label));
				i++;
			}catch(MissingResourceException e){
				eof = true;
				return selectItems;
			}
		}
		return selectItems;
	}
	
	public List<SelectItem> getAmPm(){
		List<SelectItem> selectItems = new ArrayList<SelectItem>();
		
		SelectItem am = new SelectItem(true, "am");
		SelectItem pm = new SelectItem(false, "pm");
		
		selectItems.add(am);
		selectItems.add(pm);
		
		return selectItems;
	}

}
